Help need with dialog functionality and link transfer.

Hello,
I am attempting to write a script to transfer links. I know there are scripts that do this. But the ones that I have found and attempted to use have lost links based on certain conditions. Below is my attempt to fix these flaws. Any help would be appreciated along with feedback.
• Is there a way of having a double callback for sort lists, meaning when the user attempting to sort the list the second time the list is reversed?
• Is there a way of removing and inserting columns once they have been created and populated?
• How do you set the "current Background Color" (as under the user options) on the current object?
• Is there a way to make a row inactive for selection but still allow functionality when its "Activated"
• If there a more efficient of dealing with the linkpairing descriptions within my current logic?
• I believe I know the answer to this question but I'll ask it any ways. Are there callbacks for right/left clicks?
• Is there anything that I should change with my current logic?
• Any suggestions for additional functionality would be helpful.

#include <utils/linkops.dxl>
pragma runLim, 0
 
const Module m        = current
const Folder f        = current
const string Notfound = "Notfound"
const string foundMod = "foundMod"
const string foundLnk = "foundLnk"
 
if ( null m ) {
    warningBox "Please run this script from a module."; halt
}
 
const string dummy[] = {}
DB mainDB, editDB, diffDB
DBE linkSetListView, editButton, sourceModField, targetModField, targetBrowseButton, linkModField, linkBrowseButton, optionsRadioBox, okButton, difftextbox
 
string oldLinkMod = null
string oldTgtMod  = null
Skip cLinks       = create ()
Skip LinkPairings = create ()
Buffer firstrun   = create (); firstrun  = ""
Buffer secondrun  = create (); secondrun = ""
 
int doSortString(string s1, string s2) {
    return(cistrcmp(s1, s2))
}
 
int doSortStringReverse(string s1, string s2) {
        return(cistrcmp(s2, s1))
}
 
int     doSortInt(string str1, string str2)
{
        int s1     = intOf(realOf(str1))
        int s2     = intOf(realOf(str2))
        int     Result = 0
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{}
        return(Result)
}
 
string findLinkParing(int index) {   
        LinkModuleDescriptor LMD = null
        string tgtMod            = getColumnValue(linkSetListView, index, 2)
        string linkMod           = getColumnValue(linkSetListView, index, 5)
        string ret               = Notfound
        
        for LMD in f do {
                if (getSourceName(LMD) "" == fullName(m) "" && getTargetName(LMD) "" == tgtMod) {
                        if (getTargetName(LMD) "" != linkMod) {
                                ret = foundMod
                                break
                        } else if (getTargetName(LMD) "" == linkMod) {
                                ret = foundLnk
                                break
                        }
                }
        }
        return ret
}
 
void getLinkParing() {       
        LinkModuleDescriptor LMD = null
        
        for LMD in f do {
                if (getSourceName(LMD) "" == fullName(m)"") {
                        put(LinkPairings, getTargetName(LMD) "", LMD)
                }
        }
}
 
void getLinkParingVsLinks() {        
        getLinkParing()
        
        LinkModuleDescriptor LMD = null
    Link l                   = null
        Object osrc              = null
    ModName_ otherMod        = null
    Object othero            = null
        string err               = null 
        string tgtMod            = null
        string linkMod           = null
        Skip addLinkPairings     = create ()
        
        bool isManditory         = false
        
        if(get(optionsRadioBox) == 0) {
                isManditory = true
        }
        
        for osrc in entire m do {
                if(null osrc) continue
                if(isDeleted osrc) continue
        
                for l in all(osrc->"*") do {
                        ModuleVersion otherVersion = targetVersion l
                        otherMod = module(otherVersion)
                        
                        if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                        othero = target l
                        if (null othero) {load(otherVersion,false)}
                        othero = target l
                        if (null othero) {delete otherVersion; continue}
                        if (isDeleted othero) {delete otherVersion; continue}
                        
                        LMD = null
                        if(find(LinkPairings, fullName(module(othero)) "", LMD)) {
                                delete(LinkPairings, getTargetName(LMD) "")
                        } else {
                                put(addLinkPairings, fullName(module(othero)) "" fullName(module(l)) "", l)
                        }
                        
                        delete otherVersion
                }
        }
        
        for LMD in LinkPairings do {
                err = null
                if ( confirm "WARNING: do you want to remove this [" getTargetName(LMD) "] unused Linkpairing Decription?\n\nContinue?") {
                        err = removeLinkModuleDescriptor(f, fullName(m) "", getTargetName(LMD)"")
                                                
                        if(!null err) {
                                ack err 
                        } 
                }
        }
        
        for l in addLinkPairings do {
                err     = null
                othero  = target l
                tgtMod  = fullName(module(othero))
                linkMod = fullName(module(l))
                
                if ( confirm "WARNING: do you want to add this [" tgtMod "] Linkpairing Decription?\n\nContinue?") {
                        err = addLinkModuleDescriptor(f, fullName(m) "", tgtMod, !isManditory, isManditory, linkMod, "")
                                                
                        if(!null err) {
                                ack err "\n\nPlease Check that all Link(s) go through the correct [LinkModule]!" 
                        } 
                }
        }
        
        delete addLinkPairings
}
        
void diffLinks(Buffer &skp) {
    Link l            = null
    ModName_ otherMod = null
    Object othero     = null
        Object osrc       = null
        
        //Store/Display Links
        for osrc in entire m do {
                if(null osrc) continue
                //if(isDeleted osrc) continue
        
                for l in all(osrc->"*") do {
                        ModuleVersion otherVersion = targetVersion l
                        otherMod = module(otherVersion)
                        
                        if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                        othero = target l
                        if (null othero) {load(otherVersion,false)}
                        othero = target l
                        if (null othero) {delete otherVersion; continue}
                        if (isDeleted othero) {delete otherVersion; continue}
                        if(isDeleted osrc) { skp += "Softdeleted - " }  
                        skp += fullName(module(osrc)) "-" probeAttr_(osrc,"Absolute Number") "\t=>\t" fullName(otherMod) "-" probeAttr_(othero,"Absolute Number") 
                        if (isBaseline(otherVersion)) {skp += " [" versionString(otherVersion) "]"}
                        skp += "\n"
                        
                        delete otherVersion
                }
        }
}
 
 
void getLinkSets() {
        empty(linkSetListView)
        setempty(cLinks)
        
    Link l            = null
        Object osrc       = null
        AttrDef Ad        = null
    ModName_ otherMod = null
    Object othero     = null
        string text       = null
        int cnt           = 0
        
        //Store/Display Links
        for osrc in entire m do {
                if(null osrc) continue
                //if(isDeleted osrc) continue
                
                for l in all(osrc->"*") do {
                        ModuleVersion otherVersion = targetVersion l
                        otherMod = module(otherVersion)
                        if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
                        othero = target l
                        if (null othero) {load(otherVersion,false)}
                        othero = target l
                        if (null othero) {delete otherVersion; continue}
                        if (isDeleted othero) {delete otherVersion; continue}
                                
                        insert(linkSetListView, cnt, probeAttr_(osrc,"Absolute Number"), iconNone)
                        if(isDeleted osrc) {
                                set(linkSetListView, cnt, 0, iconLinkDeleted)
                                set(linkSetListView, cnt, 7, "DELETED")
                        }
                        
                        text = "(Inaccessible)"
                        Ad = find(module othero, "Object Heading")
                        if (!null Ad and canRead(module othero, "Object Heading")) {
                                text = probeAttr_(othero, "Object Heading")
                        }
                        if (null text) {
                                Ad = find(module othero,"Object Text")
                                if(!null Ad and canRead(module othero, "Object Text")) {
                                        text = probeAttr_(othero, "Object Text")
                                } else {
                                        text = "(Inaccessible)"
                                }
                        }
                        set(linkSetListView, cnt, 1, text)
                        set(linkSetListView, cnt, 2, fullName(otherVersion))
                        set(linkSetListView, cnt, 3, probeAttr_(othero,"Absolute Number"))
                           
                        text = "(Inaccessible)"
                        Ad = find(module osrc, "Object Heading")
                        if (!null Ad and canRead(module osrc, "Object Heading")) {
                                text = probeAttr_(osrc, "Object Heading")
                        }
                        if (null text) {
                                Ad = find(module osrc, "Object Text")
                                if(!null Ad and canRead(module osrc, "Object Text")) {
                                        text = probeAttr_(osrc, "Object Text")
                                } else {
                                        text = "(Inaccessible)"
                                }
                        }
                        
                        set(linkSetListView, cnt, 4, text)
                        set(linkSetListView, cnt, 5, fullName(module(l)))
                        
                        if (isBaseline(otherVersion)) {
                                set(linkSetListView, cnt, 6, "[" versionString(otherVersion) "]")
                        }
                        
                        set(linkSetListView, cnt, 8, cnt"")
                        
                        put(cLinks, cnt++, l)
                        
                        delete otherVersion
                }
        }
}
 
void diff_(Buffer &buff1, Buffer &buff2)
{
        Buffer resBuf = create()
        diff(resBuf, buff1, buff2, "\\cf1\\strike ", "\\cf3\\ul ")
        realize diffDB 
        useRTFColour(difftextbox, true) 
        set(difftextbox, tempStringOf resBuf) 
        show diffDB
        delete resBuf 
}
 
void doUpdateLinks(DB x) {
        if (!isEdit(m) and !isShare(m)) {
                edit(fullName(m),false) 
                
                if (isRead m) {
                        warningBox "Source module '" fullName(m) "' must be open editable!"
                        return
                }
        }
        
        Link l           = null
        Object osrc      = null
        Object otgt      = null
        int max          = noElems(linkSetListView)
        int index        = 0
        int cIndex       = 0
        bool isManditory = false
        string linkMod   = get(linkModField)
        string err       = null
        string tgtMod    = null
        
        if(get(optionsRadioBox) == 0) {
                isManditory = true
        }
 
        for index in 0:max-1 do {
                cIndex     = intOf(realOf(getColumnValue(linkSetListView, index, 8)))
                tgtMod     = getColumnValue(linkSetListView, index, 2)
                oldLinkMod = getColumnValue(linkSetListView, index, 5)
                err        = null
                
                if (selected(linkSetListView,index)) {
                        if (getColumnValue(linkSetListView, index, 7) "" == "DELETED") { 
                                continue 
                        }
                        
                        if(find(cLinks, cIndex, l)) {
                                if(findLinkParing(index) == Notfound) {
                                        //infoBox("DEBUG 1")
                                        err = addLinkModuleDescriptor(f, fullName(m) "", tgtMod, !isManditory, isManditory, linkMod, "")
                                        if(!null err) {
                                                ack err 
                                        }
                                }
                                else if(findLinkParing(index) == foundMod) {
                                        //infoBox("DEBUG 2")
                                        err = removeLinkModuleDescriptor(f, fullName(m) "", tgtMod)
                                                
                                        if(!null err) {
                                                ack err 
                                        } else {
                                                err = addLinkModuleDescriptor(f, fullName(m) "", tgtMod, !isManditory, isManditory, linkMod, "")
                                                if(!null err) {
                                                        ack err 
                                                }
                                        }
                                }
                                else if(findLinkParing(index) == foundLnk) {
                                        //infoBox("DEBUG 3")
                                }
                                else {
                                        //infoBox("DEBUG Error")
                                        err = Notfound
                                }
 
                                if(linkMod != oldLinkMod && null err) {
                                        int Error = linkErrorNoError
                                                        
                                        noError()
                                                osrc = gotoObject(sourceAbsNo(l), read(fullName(m), false))
                                        err = lastError()
                                                        
                                        if (!null err) {
                                                errorBox(err)
                                                continue
                                        }
                                
                                        ModuleVersion otherVersion = targetVersion l
                                        otherMod = module(otherVersion)
                                        if (null otherMod || isDeleted otherMod) {
                                                errorBox("{Null} Object")
                                        } else {
                                                otgt = object(targetAbsNo(l), load(otherVersion,false))
                                                if (null otgt || isDeleted otgt) {
                                                        errorBox("{Null} Object")
                                                } else {
                                                        Error = createLink_(osrc, linkMod, otgt)        
                                                        if (Error != linkErrorNoError) { 
                                                                reportLinkError_(osrc, otgt, linkMod, "", Error) 
                                                        } else {
                                                                delete l
                                                        }
                                                }
                                        }
                                        delete otherVersion
                                }
                        }
                }
        }
        flushDeletions() 
        
        setempty(secondrun)
        diffLinks(secondrun)
 
        //Reset display
        getLinkSets()
 
        //Diff
        if(stringOf(firstrun) != stringOf(secondrun)) {
                diff_(firstrun, secondrun)
        }
        
        refresh(m)
        infoBox("Done!")
}
 
void closeCallback (DB x)
{
        getLinkParingVsLinks()
        
        delete firstrun
        delete secondrun
        delete cLinks
        delete LinkPairings
        
        destroy(diffDB)
        diffDB = null
        
        destroy(mainDB)
        mainDB = null
}
 
void editLinkset(DB x) {
        int sel    = get(linkSetListView)
        
        oldLinkMod = getColumnValue(linkSetListView, sel, 3)
        oldTgtMod  = getColumnValue(linkSetListView, sel, 1)
        
        set(sourceModField, fullName(m))
        set(targetModField, getColumnValue(linkSetListView, sel, 2))
        set(linkModField, getColumnValue(linkSetListView, sel, 5))
        
        //future  code....
        /*
        if(getColumnValue(linkSetListView, sel, 2) == "Manditory") {
                set(optionsRadioBox, 0) 
        } else {
                set(optionsRadioBox, 1)
        }
        */
        set(optionsRadioBox, 0)
        inactive(optionsRadioBox)
        inactive(targetModField)
        inactive(targetBrowseButton)
        
        show editDB
}
 
void openTrgMod(DB x) {
    Link l     = null
        string err = null
        int sel    = get(linkSetListView)
        int Index  = intOf(realOf(getColumnValue(linkSetListView, sel, 8)))
        
        noError()
                if(find(cLinks, Index, l)){
                        ModuleVersion otherVersion = targetVersion l
                        gotoObject(targetAbsNo(l), load(otherVersion,true))
                        delete otherVersion
                }
        err = lastError()
        
        if (!null err) {
                errorBox(err)
        }
}
 
void targetPathCB (DBE) {
        Item i = item fnMiniExplorer(editDB,MINI_EXP_FORMAL_MODS,null,null)
        
        if(!null i) {
                set(targetModField, fullName i) 
        }
}
 
void linkPathCB (DBE) {
        Item i = item fnMiniExplorer(editDB,MINI_EXP_LINK_MODS,null,null)
        
        if(!null i) {
                set(linkModField, fullName i) 
        }
}
 
void linkSelectionMade(DBE lstv, int sel) { 
        //future  code....
        active editButton 
} // linkSelectionMade
 
void linkDeselection(DBE lstv, int sel) {  
        //future  code....
        inactive editButton 
} // linkDeselection
 
void linkActivated(DBE lstv, int sel) { 
        openTrgMod(null) 
} // linkActivated
        
//diffDB        
diffDB = create("diff...", styleCentered)
difftextbox = richText(diffDB, "modifications", "", 850, 400, true)
 
//editDB        
editDB = create("Edit Linkset and Update Links...", styleCentered)
 
sourceModField = field(editDB, "Source module:", "", 30, true)
sourceModField -> "top" -> "form"; sourceModField -> "left" -> "form"; sourceModField -> "right" -> "unattached"; sourceModField -> "bottom" -> "unattached"
targetModField = field(editDB, "Target module:", "", 30, false)
targetModField -> "top" -> "flush" -> sourceModField; targetModField -> "left" -> "unattached"; targetModField -> "right" -> "aligned" -> sourceModField; targetModField -> "bottom" -> "unattached"
 
targetBrowseButton = button(editDB, "Browse...", targetPathCB)
targetBrowseButton -> "top" -> "aligned" -> targetModField; targetBrowseButton -> "left" -> "flush" -> targetModField; targetBrowseButton -> "right" -> "unattached"; targetBrowseButton -> "bottom" -> "unattached"
 
linkModField = field(editDB, "Link module:", "", 30, false)
linkModField -> "top" -> "flush" -> targetModField; linkModField -> "left" -> "unattached"; linkModField -> "right" -> "aligned" -> targetModField; linkModField -> "bottom" -> "unattached"
 
linkBrowseButton = button(editDB, "Browse...", linkPathCB)
linkBrowseButton -> "top" -> "aligned" -> linkModField; linkBrowseButton -> "left" -> "flush" -> linkModField; linkBrowseButton -> "right" -> "unattached"; linkBrowseButton -> "bottom" -> "unattached"
 
string choices[2] = {"Manditory","Overrideable"}
optionsRadioBox = radioBox(editDB, "", choices, 0)
optionsRadioBox -> "top" -> "flush" -> linkModField; optionsRadioBox -> "left" -> "form"; optionsRadioBox -> "right" -> "unattached"; optionsRadioBox -> "bottom" -> "form"
okButton = ok(editDB, "OK", doUpdateLinks)
 
//mainDB
mainDB = create("Show Module Links..." , styleCentered)
 
linkSetListView = listView(mainDB, listViewOptionMultiselect|listViewOptionSortText, 1180, 15, dummy) //listViewOptionSortText, listViewOptionMultiselect
linkSetListView -> "top" -> "form"; linkSetListView -> "left" -> "form"; linkSetListView -> "right" -> "form"; linkSetListView -> "bottom" -> "form"
set(linkSetListView, linkSelectionMade, linkDeselection, linkActivated)
 
editButton = apply(mainDB, "Edit", editLinkset); inactive(editButton) 
close (mainDB, true, closeCallback)
realize(mainDB)
 
insertColumn(linkSetListView, 0, "ID", 60, iconNone); set(linkSetListView, 0, doSortInt) // Allow sorting this column
insertColumn(linkSetListView, 1, "Object Heading/Text", 150, iconNone)
insertColumn(linkSetListView, 2, "Target Module", 300, iconFormal); set(linkSetListView, 2, doSortString) // Allow sorting this column
insertColumn(linkSetListView, 3, "ID", 60, iconNone); set(linkSetListView, 3, doSortInt) // Allow sorting this column
insertColumn(linkSetListView, 4, "Object Heading/Text", 150, iconNone)
insertColumn(linkSetListView, 5, "Link Module", 250, iconLink); set(linkSetListView, 5, doSortString) // Allow sorting this column
insertColumn(linkSetListView, 6, "Baseline", 90, iconNone); set(linkSetListView, 6, doSortStringReverse) // Allow sorting this column
insertColumn(linkSetListView, 7, "Status", 90, iconNone); set(linkSetListView, 7, doSortStringReverse) // Allow sorting this column
insertColumn(linkSetListView, 8, "Index", 90, iconNone); set(linkSetListView, 8, doSortInt) // Allow sorting this column
 
setempty(firstrun)
diffLinks(firstrun)
 
getLinkSets()
show(mainDB)

 


-Jim

 


SystemAdmin - Thu Mar 14 01:19:58 EDT 2013

Re: Help need with dialog functionality and link transfer.
llandale - Thu Mar 14 15:32:09 EDT 2013

I would suppose the following would work:

bool SortLowToHigh = true
 
int dxlSortFn(string s1, string s2){
   int RetValue
   if(s1==s2) then RetValue = 0  
   elseif(s1>s2) then RetValue = 1  
   else -1
   if (!SetLowToHigh) then RetValue = RetValue*-1
   SetLowToHigh = !SetLowToHigh
}


-Louie

Re: Help need with dialog functionality and link transfer.
SystemAdmin - Thu Mar 14 18:02:42 EDT 2013

Hello,

I made modification to my file, but I seem to have issues with the 'diff()' function. Where if I have large buffers to diff it doesn't display the differences but when I choose a small subset of information to diff I get what I expect. Is there a limitation and if so what would be the best approach to diff the buffer to get the results I'm looking for? Thank you.
-Jim
Attachments

attachment_14957051_transferLinks.dxl

Re: Help need with dialog functionality and link transfer.
llandale - Fri Mar 15 12:31:15 EDT 2013

SystemAdmin - Thu Mar 14 18:02:42 EDT 2013
Hello,

I made modification to my file, but I seem to have issues with the 'diff()' function. Where if I have large buffers to diff it doesn't display the differences but when I choose a small subset of information to diff I get what I expect. Is there a limitation and if so what would be the best approach to diff the buffer to get the results I'm looking for? Thank you.
-Jim

Yes "diff" has limits. I don't recall what the developer's told me some years ago but it looked like "diff can handle only 1000 different words ..err.. tokens". My notes recommend don't use it for information 5kb or larger.

You do not want to "diff" rich text anyway, so if you retrieve the raw text from an attribute you are fine.

Before "diff" there was DXL written "deltaBuff.dxl" code; which was terribly slow and I would expect be unacceptable for these large files as well. My ancient file compare program uses the old DOS "fc.exe" which produces reports that are hard to read.

-Louie

"deltaText.dxl" was far worse and couldn't be used for more than one compare per context. ..err.. without modification.